package com.example.test.controller;

import com.example.test.entity.Image;
import com.example.test.service.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/images")
@CrossOrigin
public class ImageController {

    @Autowired
    private ImageService imageService;

    @PostMapping("/{productId}")
    public void uploadImages(@PathVariable Long productId, @RequestParam("files") List<MultipartFile> files) throws IOException {
        imageService.uploadImages(productId, files);
    }

    @GetMapping("/{productId}")
    public List<String> getProductImages(@PathVariable Long productId) {
        return imageService.getProductImages(productId);
    }

    @DeleteMapping("/product/{productId}")
    public void deleteProductImages(@PathVariable Long productId) {
        imageService.deleteProductImagesByProductId(productId);
    }
    @GetMapping("/img/{productId}")
    public List<Image> getProductImagesByProductId(@PathVariable Long productId) {
        return imageService.getProductImagesByProductId(productId);
    }
}

